//
//  AddGroupTableViewCell.m
//  Findif
//
//  Created by Mac on 2019/2/20.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "AddGroupTableViewCell.h"

@interface AddGroupTableViewCell ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, strong)UILabel * oneLabel;
@property (nonatomic, strong)UILabel * twoLabel;
@property (nonatomic, strong)UILabel * threeLabel;
@property (nonatomic, strong)UILabel * fourLabel;
@property (nonatomic, weak)UILabel * exploreLabel;

@end

@implementation AddGroupTableViewCell


- (void)setModel:(GroupModel *)model{
    
    _model = model;
    
    self.backView.frame = CGRectMake(0, 0, kScreenW, 60 * SCREENH6);
    
    self.nameLabel.text = model.group_name;
    
    if (model.group_desc) {
        
        self.exploreLabel.text = model.group_desc;
    }else{
        
        self.exploreLabel.text = @"该社团还未添加任何介绍";
    }
    NSString * iconStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,model.group_img];
    NSURL * iconUrl = [NSURL URLWithString:iconStr];
    [self.iconImageView sd_setImageWithURL:iconUrl];
    
    NSArray *array = [model.group_category_name componentsSeparatedByString:@","];
    
    CGFloat x = 60 * SCREENH6;
    CGFloat y = 22 * SCREENH6;
    CGFloat width = 35 * SCREENH6;
    CGFloat height = 15 * SCREENH6;
    CGFloat space = 5 * SCREENH6;
    for (int i = 0; i < array.count; i++) {

        UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(i * (width + space) + x, y, width, height)];

        NSString * title = [NSString stringWithFormat:@" %@ ",array[i]];
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:11 * SCREENH6];
        button.layer.cornerRadius = 7 * SCREENH6;
        button.layer.masksToBounds = YES;
        if ([title isEqualToString:@" 吃喝 "]) {

            [button setBackgroundColor:ColorWithRGB(0xEB7664)];
        }else if ([title isEqualToString:@" 玩乐 "]){

            [button setBackgroundColor:ColorWithRGB(0xAD77E9)];
        }else if ([title isEqualToString:@" 运动 "]){

            [button setBackgroundColor:ColorWithRGB(0x72D9AA)];
        }else if ([title isEqualToString:@" 旅行 "]){

            [button setBackgroundColor:ColorWithRGB(0x6AA3F1)];
        }
        
        [self.backView addSubview:button];
    }
    
}


- (void)setPushSquareModel:(GroupModel *)pushSquareModel{
    
    _pushSquareModel = pushSquareModel;
    
    self.backView.frame = CGRectMake(15, 0, 345 * SCREENH6, 60 * SCREENH6);
    
    self.nameLabel.text = pushSquareModel.group_name;
    
    if (pushSquareModel.group_desc) {
        
        self.exploreLabel.text = pushSquareModel.group_desc;
    }else{
        
        self.exploreLabel.text = @"该社团还未添加任何介绍";
    }
    NSString * iconStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,pushSquareModel.group_img];
    NSURL * iconUrl = [NSURL URLWithString:iconStr];
    [self.iconImageView sd_setImageWithURL:iconUrl];
    
    NSArray *array = [pushSquareModel.group_category_name componentsSeparatedByString:@","];
    
    CGFloat x = 60 * SCREENH6;
    CGFloat y = 22 * SCREENH6;
    CGFloat width = 35 * SCREENH6;
    CGFloat height = 15 * SCREENH6;
    CGFloat space = 5 * SCREENH6;
    for (int i = 0; i < array.count; i++) {
        
        UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(i * (width + space) + x, y, width, height)];
        
        NSString * title = [NSString stringWithFormat:@" %@ ",array[i]];
        [button setTitle:title forState:UIControlStateNormal];
        [button setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:11 * SCREENH6];
        button.layer.cornerRadius = 7 * SCREENH6;
        button.layer.masksToBounds = YES;
        if ([title isEqualToString:@" 吃喝 "]) {
            
            [button setBackgroundColor:ColorWithRGB(0xEB7664)];
        }else if ([title isEqualToString:@" 玩乐 "]){
            
            [button setBackgroundColor:ColorWithRGB(0xAD77E9)];
        }else if ([title isEqualToString:@" 运动 "]){
            
            [button setBackgroundColor:ColorWithRGB(0x72D9AA)];
        }else if ([title isEqualToString:@" 旅行 "]){
            
            [button setBackgroundColor:ColorWithRGB(0x6AA3F1)];
        }
        
        [self.backView addSubview:button];
    }
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(15 * SCREENH6, 5 * SCREENH6, 345 * SCREENH6, 60 * SCREENH6)];
    
    backView.backgroundColor = ZRWhiteColor;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.layer.cornerRadius = 20 * SCREENH6;
    iconImageView.layer.masksToBounds = YES;
    iconImageView.backgroundColor = [UIColor lightGrayColor];
    
    self.iconImageView = iconImageView;
    
    [self.backView addSubview:self.iconImageView];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.textColor = ZRBlackColor;
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    nameLabel.text = @"sdcsdfsf";
    
    self.nameLabel = nameLabel;
    
    [self.backView addSubview:self.nameLabel];
    
    
    UILabel * exploreLabel = [UILabel new];
    
    exploreLabel.textColor = ColorWithRGB(0x909090);
    exploreLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    exploreLabel.text = @"sdfasfasfsdcasdcaf";
    
    self.exploreLabel = exploreLabel;
    
    [self.backView addSubview:self.exploreLabel];
}


-(void)layoutSubviews{
    
//    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.centerX.mas_equalTo(self.contentView);
//        make.width.mas_equalTo(345 * SCREENH6);
//        make.height.mas_equalTo(60 * SCREENH6);
//    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.leading.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.height.width.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.backView).offset(3 * SCREENH6);
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.exploreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.backView).offset(-5 * SCREENH6);
        make.leading.mas_equalTo(self.nameLabel);
        make.trailing.mas_equalTo(self.backView).offset(-10 * SCREENH6);
    }];
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
